<script type="text/javascript">
var s_l_a_nowrow=0;
var s_l_a_uid;
var s_l_a_classid;
var s_l_a_isclass;
$(document).ready(function(){
	var data = JSON.parse($(".s_temple_setting.activity_list_settings").html());
	$(".s_l_a_g_header").html (data.header);
	$(".s_l_a_main_entry").addClass("active");
	s_l_a_uid = data.uid;
	if(isOwner()){
	s_l_a_isclass = data.isclass;
	readClassList();
	if(s_l_a_isclass){
		s_l_a_classid = data.classid;
		$(".s_h_l_"+s_l_a_classid).addClass("active");
	}else{
		$(".s_h_l_own").addClass("active");
	}}else
	{
		$(".s_l_a_topbar").hide();
	}
	$(".s_l_a_load_more").click();
	$.cookie('s_a_d_can_back', 'true');

});
function readClassList(){
	classdata = getClassData();
	if(classdata.isStudent){
		$(".s_l_a_classes").append($("<div class='header'>").html("学生所属班级："));
		$classid = classdata["class"]["classid"];
		$classname = classdata["class"]["displayname"];
		add_Class($classid,$classname);	loadAjaxEntry();
		return;
	}
	var sp = false;
	if(classdata.isTeacher){
		sp=true;
		var master=-1;
		if(classdata.isMaster)
			master = classdata.masterClass;
		$(".s_l_a_classes").append($("<div class='header'>").html("教师任教班级："));
		$.each(classdata.classes,function(k,v){
			var name = v.classid==master?v.displayname+"(班主任)":v.displayname;
			add_Class(v.classid,name);
		});
	}
	if(classdata.isParent){
		if(sp){
			$(".s_l_a_classes").append("<div class='divider'>");
		}
		$(".s_l_a_classes").append($("<div class='header'>").html("子女所属班级："));
		$.each(classdata.children,function(k,v){
			var name = v.displayname+"("+v["card"]["name"]+")";
			add_Class(v.classid,name);
		});
	}
	loadAjaxEntry();
	
}
function add_Class(id,name){
	$tmp = $("<a class='item s_ajax_entry s_h_l_"+id+"' url='index.php?mod=home&childmod=home&ajax=true&op=activity_list&classid="+id+"' targetid='s_z_ajax_container'>").html(name);
	$(".s_l_a_classes").append($tmp);
}
function s_l_aloadList(list){
	var $container = $("<div id='offset-"+s_l_a_nowrow+"'>")
	$.each(list,function(k,v){
		$container.prepend(loadTemple(v));
	});
	$("#activities").append($container);
}

function s_l_a_loadMore(){
	if(s_l_a_isclass){
		ajaxRequest("offset="+s_l_a_nowrow+"&classid="+s_l_a_classid,"index.php?mod=home&childmod=home&ajax=true&op=activity_load_more_class",s_l_a_onSuccess,s_l_a_onError);
		return;
	}
	console.log(s_l_a_uid);
	ajaxRequest("offset="+s_l_a_nowrow+"&uid="+s_l_a_uid,"index.php?mod=home&childmod=home&ajax=true&op=activity_load_more",s_l_a_onSuccess,s_l_a_onError);
	
}

function s_l_a_onSuccess(data){
	s_l_a_operatedone(data.code,data.message,data.data);
}
function s_l_a_onError(data){
	console.log(data);
	s_l_a_operatedone(-101,"服务器返回了未知的数据，请上报管理员",data.responseText);
}
function s_l_a_operatedone(id,message,data){
	updateScroll();
	if(id==-101){	
		$(".s_l_a_message").html(message+"<br><br><pre>"+data+"</pre>");
	$(".s_l_a_modal").modal("show");
	return;}
	if(data.op=="load_more"){
		if(data.bottom){
			$(".s_l_a_load_more").html("到底了");
			$(".s_l_a_load_more").addClass("disabled");
		}
		console.log(data.data);
		s_l_aloadList(data.data);
		s_l_a_nowrow +=data.amount;
	}
	console.log(data.op);
	if(data.op=="request"){
		mainPageLoad(data.url);
	}
	if(data.op=="remove"){
		aid = data.aid;
		$("#"+aid).remove();
	}
	if(data.close!=true){
		$(".s_l_a_message").html(message);
		$(".s_l_a_modal").modal("show");
	}
	reloadScroll();
}

function s_i_a_loadDetial(e){
	aid = e.attr("aid");
	mainPageLoad("index.php?mod=home&childmod=home&ajax=true&op=activity&aid="+aid);
}
function s_l_a_remove(e){
	var aid = e.attr("aid")
		ajaxRequest("op=removeActivityFormList&aid="+aid,"index.php?mod=home&childmod=home&ajax=true&op=activity_operate",s_l_a_onSuccess,s_l_a_onError);
}
function loadTemple(data){
	var $tmp = $("#activetemple").clone();
	$tmp.attr("id",data.aid).attr("style","");
	$tmp.find(".s_l_a_autherhead").attr("src",data.card.head_image_path);
	$tmp.find(".s_l_a_authername").attr("href",getHomeURL(data.uid)).html(data.card.name);
	$tmp.find(".s_a_l_head").html(data.subject);
	$tmp.find(".s_l_a_content").html(data.content);
	$tmp.find(".s_l_a_admin").attr("aid",data.aid);
	 content = data.content.replace(/\n|\r\n/g, "<br>")
	  $tmp.find(".s_l_a_content").html(content);
	    index = getIndex(content,"<br>",3);
	    if(index>=content.length){
	    	$tmp.find(".s_text_shower").attr("aid",data.aid).hide();
	    }else{
	    	$tmp.find(".s_text_shower").addClass("enabled").attr("aid",data.aid);
	    	s_short = content.substring(0,index).replace(/\n|\r\n/g, "<br>")+"......";
	    	$tmp.find(".s_l_a_content").attr("short",s_short).attr("all",content).html(s_short);
	    }
	if(!data.allowComment){
		$tmp.find(".s_l_a_reply").hide();
	}
	if(!data.isAdmin){
		$tmp.find(".s_adminbar").hide();
	}
	if(data.commentsamount!=0){
		$tmp.find(".s_l_a_detial").html("查看"+data.commentsamount+"条评论").attr("aid",data.aid);
	}else{
		$tmp.find(".s_l_a_detial").html("查看详情").attr("aid",data.aid);
	}
	$tmp.find(".s_l_a_comment_reply_aid").attr("value",data.aid);
	 bindAjaxForm($tmp.find(".s_l_a_reply"),s_l_a_onSuccess,s_l_a_onError);
	$tmp.find(".s_l_a_time").html(data.date);
	if(data.view_level==0)
		$tmp.find(".s_private").hide();
	return $tmp;
}
function s_l_toggle_content(to){
	if(!to.hasClass("enabled")){
		return;
	}
	aid = to.attr("aid");
	if(to.hasClass("s_text_hidden")){
		to.removeClass("s_text_hidden").removeClass("s_text_showed");
		container = $("#"+aid).find(".ui.text.container").find(".s_l_a_content");
		container.html(container.attr("all"));
		to.html("收起");
	}else{
		to.removeClass("s_text_showed").addClass("s_text_hidden");
		container = $("#"+aid).find(".ui.text.container").find(".s_l_a_content");
		container.html(container.attr("short"));
		to.html("展开");
	}
}
</script>
<h3 class="s_l_a_g_header"></h3>
<div class="s_temple_setting activity_list_settings"><?php print_json_setting("activity_list");?></div>
<div class="ui two item menu s_l_a_topbar">
	<a class="item s_ajax_entry s_h_l_own" id="" url="index.php?mod=home&childmod=home&ajax=true&op=activity_list&uid=<?php getSessionUid();?>" targetid="s_z_ajax_container">我的动态</a>
	<div class="ui simple dropdown item s_h_l_class">
		班级动态
		<i class="dropdown icon"></i>
		<div class="menu s_l_a_classes"></div>
	</div>
</div>
<div id="activities"></div>
<button class="ui fluid button s_l_a_load_more" onClick="if($(this).hasClass('disabled'))return; s_l_a_loadMore()">加载更多</button>
<div class="s_l_a_activity" id="activetemple" style="display: none;">
	<div class="ui top attached block header inline">
		<img class="ui avatar image s_l_a_autherhead">
		<span>
			<a class="s_l_a_authername s_activity_name"></a>
		</span>
		<span class="s_private">
			<i class="lock icon"></i>
			私有动态
		</span>
	</div>
	<div class="ui bottom attached segment">
		<div class="ui text container" style="padding-down: 0.4cm">
			<h2 class="ui header s_a_l_head">标题</h2>
			<div class="s_l_a_content"></div>
		</div>
		<div class="s_actionbar">
			<div class="s_inline s_l_a_time"></div>
			<div class="s_inline s_text_shower s_text_hidden s_right_float" onClick="s_l_toggle_content($(this))">展开</div>
		</div>
		<div class="s_actionbar s_adminbar">
			<div class="s_inline">管理选项：</div>
			<div class="s_division"></div>
			<div class="s_inline s_l_a_admin" onClick="s_l_a_remove($(this))">删除</div>
		</div>
		<hr />
		<div class="s_append_images ui images"></div>
		<a class="s_l_a_detial" onClick="s_i_a_loadDetial($(this))"></a>
		<form class="s_l_a_reply s_simple_reply s_comment_entry" url="index.php?mod=home&childmod=home&ajax=true&op=replyactivity" id="s_l_a_comment_reply">
			<input type="hidden" class="s_l_a_comment_reply_aid" name="aid">
			<div class="ui action fluid input">
				<input class="s_text" type="text" name="content" placeholder="回复...">
				<button class="ui button submit" type="submit">确定</button>
			</div>
		</form>
	</div>
</div>
<div class="ui modal s_l_a_modal">
	<div class="header">提示消息</div>
	<div class="content">
		<div class="description s_l_a_message"></div>
	</div>
	<div class="actions">
		<div class="ui button" onClick="$('.s_l_a_modal').modal('hide')">了解</div>
	</div>
</div>